package com.ruoyi.project.modules.questionInfo.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.modules.questionInfo.domain.QuestionInfo;
import com.ruoyi.project.modules.questionInfo.service.IQuestionInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 问题信息Controller
 *
 * @author smallrain
 * @date 2021-12-06
 */
@Controller
@RequestMapping("/questionInfo/questionInfo")
public class QuestionInfoController extends BaseController {
    private String prefix = "questionInfo/questionInfo";

    @Autowired
    private IQuestionInfoService questionInfoService;

    //@RequiresPermissions("questionInfo:questionInfo:view")
    @GetMapping()
    public String questionInfo() {
        return prefix + "/questionInfo";
    }

    /**
     * 查询问题信息列表
     */
    //@RequiresPermissions("questionInfo:questionInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QuestionInfo questionInfo) {
        startPage();
        List<QuestionInfo> list = questionInfoService.selectQuestionInfoList(questionInfo);
        return getDataTable(list);
    }

    /**
     * 导出问题信息列表
     */
    @RequiresPermissions("questionInfo:questionInfo:export")
    @Log(title = "问题信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QuestionInfo questionInfo) {
        List<QuestionInfo> list = questionInfoService.selectQuestionInfoList(questionInfo);
        ExcelUtil<QuestionInfo> util = new ExcelUtil<QuestionInfo>(QuestionInfo.class);
        return util.exportExcel(list, "问题信息数据");
    }

    /**
     * 新增问题信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存问题信息
     */
    //@RequiresPermissions("questionInfo:questionInfo:add")
    @Log(title = "问题信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody QuestionInfo questionInfo) {
        return toAjax(questionInfoService.insertQuestionInfo(questionInfo));
    }

    /**
     * 修改问题信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        QuestionInfo questionInfo = questionInfoService.selectQuestionInfoById(id);
        mmap.put("questionInfo", questionInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存问题信息
     */
    //@RequiresPermissions("questionInfo:questionInfo:edit")
    @Log(title = "问题信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QuestionInfo questionInfo) {
        return toAjax(questionInfoService.updateQuestionInfo(questionInfo));
    }

    /**
     * 删除问题信息
     */
    //@RequiresPermissions("questionInfo:questionInfo:remove")
    @Log(title = "问题信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(questionInfoService.deleteQuestionInfoByIds(ids));
    }
}
